//
//  AllOrderViewController.m
//  ZiJinLian
//
//  Created by 🐛 on 2017/5/12.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "AllOrderViewController.h"
#import "OrdersTableViewCell.h"
#import "SDAutoLayout.h"
#import "UIView+Extension.h"
#import "OrderDetailViewController.h"
#import "UserOrderModle.h"
#import "LogisticsViewController.h"
#import "PayViewController.h"
#import "SalesViewController.h"
#import "NearDetailViewController.h"
@interface AllOrderViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;
@property (nonatomic, strong) UserOrderModle *orderModle;
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UIButton *lastBtn;
@property (nonatomic, strong) NSArray  *imgAray;
@property (nonatomic ,strong) NSMutableArray *orderArray;
@property (nonatomic ,strong) UIView *blankView;
@end

@implementation AllOrderViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    [self.orderArray removeAllObjects];
    if (self.lastBtn.tag ==1) {
        [self loadOrderList:100];
    }else if(self.lastBtn.tag ==0){
        [self loadOrderList];
    }else if(self.lastBtn.tag ==2){
        [self loadOrderList:603];
    }else if(self.lastBtn.tag ==3){
        [self loadOrderList:600];
    }else if(self.lastBtn.tag ==4){
        [self loadOrderList:700];
    }else{
        switch (self.stype) {
            case 0:
            {
                [self loadOrderList];
            }
                break;
            case 1:
            {
                [self loadOrderList:100];
                self.title=MyString(@"待付款");
            }
                break;
                
            case 2:
            {
                [self loadOrderList:603];
                self.title=MyString(@"待发货");
            }
                break;
            case 3:
            {
                [self loadOrderList:600];
                self.title=MyString(@"待收货");
            }
                break;
            case 4:
            {
                [self loadOrderList:9];
                self.title=MyString(@"退货");
            }
                break;
            default:
                break;
        }

    }
    [self showNav];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"icon_back"] style:UIBarButtonItemStyleDone target:self action:@selector(backAction)];
    
}
-(void)backAction{
    
    UIViewController *viewCtl = self.navigationController.viewControllers[0];
    [self.navigationController popToViewController:viewCtl animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=MyString(@"我的订单");
    self.view.backgroundColor=Gray_Color;
    self.orderArray=[[NSMutableArray alloc]init];
    [self creatUI];
    [self.view addSubview:self.tableView];
    self.blankView=[ZJUITools showBlankView];
    self.blankView.frame=CGRectMake(0, 59, MainW, MainH-64-59);
    self.blankView.hidden=YES;
    [self.view addSubview:self.blankView];
    
    // Do any additional setup after loading the view.
}
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView= [[UITableView alloc] initWithFrame:CGRectMake(0, 59, MainW, MainH-64-59) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor=Gray_Color;
        _tableView.separatorColor=SeparatorColor;
        [_tableView registerNib:[UINib nibWithNibName:@"OrdersTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"OrdersCell"];
    }
    return _tableView;
}
- (void)creatUI{
    UIScrollView *view=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, MainW, 49)];
    view.contentSize=CGSizeMake(MainW, 49);
    view.pagingEnabled=NO;
    view.backgroundColor=[UIColor whiteColor];
    view.showsHorizontalScrollIndicator=NO;
    [self.view addSubview:view];
    UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(0, 49, MainW, 10)];
    view1.backgroundColor=Gray_Color;
    [self.view addSubview:view1];
    CGFloat width=0;
    float btnWidth = 0;
    NSArray *array=@[MyString(@"全部"),MyString(@"待付款"),MyString(@"待发货"),MyString(@"待收货"),MyString(@"已完成")];
    for (int i=0; i<5; i++) {
         CGSize size=[array[i] sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}];
        
        if (size.width>MainW/5) {
            width=size.width+10;
        }else{
            width=MainW/5;
        }
        UIButton *btn=[[UIButton alloc]init];
        [btn setTitleColor:Red_Color forState:UIControlStateSelected];
        [btn setTitleColor:TextColor3 forState:UIControlStateNormal];
        
        if (i==self.stype) {
            btn.selected=YES;
            self.lastBtn=btn;
        }
        btn.width=width;
        btn.y=0;
        btn.bsg_height=49;
        if (i==0)
        {
            btn.x = 0;
            btnWidth = CGRectGetMaxX(btn.frame);
        }
        else{
            btnWidth += CGRectGetMaxX(btn.frame);
            btn.x += btnWidth - btn.bsg_width;
        }
        [btn setTitle:array[i] forState:UIControlStateNormal];
        [btn setTitleColor:Red_Color forState:UIControlStateHighlighted];
        btn.titleLabel.font=FontAndStyle14;
        btn.tag=i;
        [btn addTarget:self action:@selector(ordersStypleClick:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:btn];
    }
    view.contentSize=CGSizeMake(btnWidth, 49);
    self.line=[[UIView alloc]initWithFrame:CGRectMake(10, 48, 50, 1)];
    self.line.bsg_centerX=self.lastBtn.bsg_centerX;
    self.line.backgroundColor=Red_Color;
    [view addSubview:self.line];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.orderArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 50;
}
//   判断
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    self.orderModle=self.orderArray[section];
    UIView * view =[[UIView alloc] initWithFrame:CGRectMake(0, 0, MainW, 50)];
    view.backgroundColor = [UIColor whiteColor];
    UILabel * nameNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, 200, 50)];
    nameNumLabel.text = [NSString stringWithFormat:@"%@：%@",MyString(@"订单号"),self.orderModle.orderSn];
    nameNumLabel.textColor=TextColor3;
    nameNumLabel.font = FontAndStyle14;
    [view addSubview:nameNumLabel];
    
    UILabel * stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(MainW-10-60, 0, 60, 50)];
    stateLabel.textAlignment = NSTextAlignmentRight ;
    stateLabel.text=MyString(@"待收货");
    stateLabel.hidden=NO;
    stateLabel.textColor = Red_Color;
    stateLabel.font =FontAndStyle14;
    [view addSubview:stateLabel];
    UIImageView *statueImg=[[UIImageView alloc]initWithFrame:CGRectMake(MainW-64, 0, 54, 40)];
    statueImg.image=[UIImage imageNamed:@"img_complete"];
    statueImg.hidden=YES;
    [view addSubview:statueImg];
    switch ([self.orderModle.status intValue]) {
        case 10:
        {
            stateLabel.text=MyString(@"待付款");
        }
            break;
        case 11:
        {
            stateLabel.text=MyString(@"待付定金");
        }
            break;
        case 50:
        {
            stateLabel.text=MyString(@"待付尾款");
        }
            break;
        case 45:
        {
            stateLabel.text=MyString(@"待到店");
        }
            break;
        case 80:
        {
            stateLabel.text=MyString(@"待发货");
        }
            break;
        case 90:
        {
            stateLabel.text=MyString(@"待收货");
        }
            break;
        case 200:
        {
            stateLabel.hidden=YES;
            statueImg.hidden=NO;
        }
            break;
        case 300:
        {
            stateLabel.text=MyString(@"交易取消");
        }
            break;
        case 35:
        {
            stateLabel.text=MyString(@"待接单");
        }
            break;
        default:
            break;
    }
    CGSize size=[stateLabel.text sizeWithAttributes:@{NSFontAttributeName:stateLabel.font }];
    stateLabel.frame=CGRectMake(MainW-10-size.width, 0, size.width, 50);
    if (stateLabel.hidden) {
        nameNumLabel.frame=CGRectMake(10, 0, MainW-30-54, 50);
    }else{
        nameNumLabel.frame=CGRectMake(10, 0, MainW-30-stateLabel.bsg_width, 50);
    }
    return view;
}
//   根据类型判断
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    self.orderModle=self.orderArray[section];
    if ([self.orderModle.status intValue]==80||[self.orderModle.status intValue]==35) {
        return 60;
    }
    return 110;
}
//   根据类型判断
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
     self.orderModle=self.orderArray[section];
    //NSArray *array=self.orderModle.items;
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MainW, 49+49)];
    
    UIView * shopView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MainW, 49)];
    shopView.backgroundColor = [UIColor whiteColor];
    [view addSubview:shopView];
    UILabel*shopPrice=[[UILabel alloc]init];
    shopPrice.text=[NSString stringWithFormat:@"¥ %@",self.orderModle.downPayment];
    shopPrice.textColor=Red_Color;
    shopPrice.font=[UIFont systemFontOfSize:15];
    CGSize size=[shopPrice.text sizeWithAttributes:@{NSFontAttributeName:shopPrice.font}];
    shopPrice.frame=CGRectMake(MainW-size.width-10, 0, size.width, 49);
    [shopView addSubview:shopPrice];
    UILabel * shopNum = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, MainW-size.width-15, 49)];
    shopNum.backgroundColor = [UIColor whiteColor];
    shopNum.text = [NSString stringWithFormat:@"%@%@%@  %@:",MyString(@"总共"),self.orderModle.quantity,MyString(@"件商品"),MyString(@"实际付款")];
    shopNum.textColor = UIColorFromRGB(0x5d5d63);
    shopNum.textAlignment = NSTextAlignmentRight;
    shopNum.font =FontAndStyle12;
    [shopView addSubview:shopNum];
    
    
    UIView * btnView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, MainW, 49)];
    btnView.backgroundColor = [UIColor whiteColor];
    [view addSubview:btnView];
    //最右边的
    UIButton * moneyBtn = [[UIButton alloc] initWithFrame:CGRectMake(MainW-13-70, 15, 70, 20)];
    moneyBtn.layer.borderColor = Red_Color.CGColor;
    moneyBtn.layer.borderWidth = 0.5;
    moneyBtn.titleLabel.font = FontAndStyle14;
    [moneyBtn setTitleColor:Red_Color forState:UIControlStateNormal];
    moneyBtn.tag = section;
    [moneyBtn addTarget:self action:@selector(lookWuLiouBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [moneyBtn setTitle:MyString(@"确认收货") forState:UIControlStateNormal];
    ViewRadius(moneyBtn, 2);
    [btnView addSubview:moneyBtn];
    //中间的
    UIButton * orderBtn = [[UIButton alloc] initWithFrame:CGRectMake(MainW-70-13-8-70, moneyBtn.y, 70, 20)];
    
    orderBtn.layer.borderColor = Red_Color.CGColor;
    orderBtn.layer.borderWidth = 0.5;
    orderBtn.titleLabel.font = FontAndStyle14;
    [orderBtn setTitleColor:Red_Color forState:UIControlStateNormal];
    orderBtn.tag = section;
    [orderBtn addTarget:self action:@selector(sureShouHuoBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [orderBtn setTitle:MyString(@"查看物流") forState:UIControlStateNormal];
    ViewRadius(orderBtn, 2);
    [btnView addSubview:orderBtn];
    //最左边的
    UIButton * orderBtn2 = [[UIButton alloc] initWithFrame:CGRectMake(MainW-70-13-8-70-78, moneyBtn.y, 70, 20)];
    
    orderBtn2.layer.borderColor = TextColor6.CGColor;
    orderBtn2.layer.borderWidth = 0.5;
    orderBtn2.titleLabel.font = FontAndStyle14;
    [orderBtn2 setTitleColor:TextColor6 forState:UIControlStateNormal];
    orderBtn2.tag = section;
    orderBtn2.hidden=YES;
    [orderBtn2 addTarget:self action:@selector(deleteOrderBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [orderBtn2 setTitle:MyString(@"删除订单") forState:UIControlStateNormal];
    ViewRadius(orderBtn2, 2);
    [btnView addSubview:orderBtn2];
    switch ([self.orderModle.status intValue]) {
            case 10:
        {
            [moneyBtn setTitle:MyString(@"确认付款") forState:UIControlStateNormal];
            orderBtn.hidden=YES;
        }
            break;
        case 11:
        {
            [moneyBtn setTitle:MyString(@"确认付款") forState:UIControlStateNormal];
            orderBtn.hidden=YES;
        }
            break;
        case 50:
        {
            [moneyBtn setTitle:MyString(@"确认付款") forState:UIControlStateNormal];
            orderBtn.hidden=YES;
        }
            break;
            
            case 80:
        {
            view.frame=CGRectMake(0, 0, MainW, 50);
            btnView.hidden=YES;
        }
        case 35:
        {
            view.frame=CGRectMake(0, 0, MainW, 50);
            btnView.hidden=YES;
        }
            break;
        case 45:
        {
            orderBtn.hidden=YES;
            [moneyBtn setTitle:MyString(@"已到店") forState:UIControlStateNormal];
        }
            break;
            case 90:
        {
            [moneyBtn setTitle:MyString(@"查看物流") forState:UIControlStateNormal];
            [orderBtn setTitle:MyString(@"确认收货") forState:UIControlStateNormal];
        }
            break;
        case 200:
        {
            orderBtn2.hidden=NO;
            [moneyBtn setTitle:MyString(@"申请售后") forState:UIControlStateNormal];
            [orderBtn setTitle:MyString(@"再次购买") forState:UIControlStateNormal];
        }
            break;
        case 300:
        {
            [moneyBtn setTitle:MyString(@"再次购买") forState:UIControlStateNormal];
            [orderBtn setTitle:MyString(@"删除订单") forState:UIControlStateNormal];
            orderBtn.layer.borderColor = TextColor6.CGColor;
            orderBtn.layer.borderWidth = 0.5;
            ViewRadius(moneyBtn, 2);
            [orderBtn setTitleColor:TextColor6 forState:UIControlStateNormal];
            
        }
            break;
            
        default:
            break;
    }

    return view;
}
-(void)deleteOrderBtnClick:(UIButton *)sender{
    
    self.orderModle=self.orderArray[sender.tag];
    LXAlertView *alert=[[LXAlertView alloc]initWithTitle:MyString(@"提示!") message:MyString(@"确定删除该订单?") cancelBtnTitle:MyString(@"取消") otherBtnTitle:MyString(@"确定") clickIndexBlock:^(NSInteger clickIndex) {
        if (clickIndex==1) {
            [self deleteOrder:self.orderModle.orderSn];
            
        }
    }];
    [alert showLXAlertView];
    //NSLog(@"删除订单");
}
//右边边
-(void)lookWuLiouBtnClick:(UIButton *)sender{
    self.orderModle=self.orderArray[sender.tag];
    switch ([self.orderModle.status intValue]) {
        case 10:
        {
            [self loadMergeRequest:sender];
            //NSLog(@"确认付款");
        }
            break;
        case 11:
        {
            [self loadMergeRequest:sender];
            //NSLog(@"定金");
        }
            break;
        case 50:
        {
            [self loadMergeRequest:sender];
            //NSLog(@"尾款");
        }
            break;
        case 80:
        {
            EaseMessageViewController*vc=[[EaseMessageViewController alloc]initWithConversationChatter:[NSString stringWithFormat:@"%@",self.orderModle.sellerId] conversationType:EMConversationTypeChat];
            vc.title=[NSString stringWithFormat:@"%@",self.orderModle.sellerId];
            [self.navigationController pushViewController:vc animated:YES];
            [self ContactCustomerService:self.orderModle.sellerIm];
            //NSLog(@"联系客服");
        }
            break;
        case 35:
        {
            
            NSLog(@"待接单的取消订单");
        }
            break;
        case 45:
        {
            [self nearReachRequest:self.orderModle.orderSn];
            NSLog(@"已到店");
        }
            break;
        case 90:
        {
            LogisticsViewController*vc=[[LogisticsViewController alloc]init];
            vc.shipperCode=self.orderModle.sellerLogistic[@"shipperCode"];
            vc.logisticCode=self.orderModle.sellerLogistic[@"logisticCode"];
            vc.orderSn=self.orderModle.orderSn;
            vc.shipperName=self.orderModle.sellerLogistic[@"shipperName"];
            vc.imgUrl=self.orderModle.items[0][@"imageUrl"];
            [self.navigationController pushViewController:vc animated:YES];
            //NSLog(@"查看物流");
        }
            break;
        case 200:
        {
            SalesViewController*vc=[[SalesViewController alloc]init];
            vc.modle=self.orderModle;
            [self.navigationController pushViewController:vc animated:YES];
            //NSLog(@"申请售后");
            
        }
            break;
        case 300:
        {
            [self buyAgain:self.orderModle.items];
            //NSLog(@"再次购买");
        }
            break;
            
        default:
            break;
    }

}
//左边
-(void)sureShouHuoBtnClick:(UIButton *)sender{
    self.orderModle=self.orderArray[sender.tag];
    switch ([self.orderModle.status intValue]) {
        case 10:
        {
            //NSLog(@"确认付款");
        }
            break;
        case 80:
        {
            EaseMessageViewController*vc=[[EaseMessageViewController alloc]initWithConversationChatter:[NSString stringWithFormat:@"%@",self.orderModle.sellerId] conversationType:EMConversationTypeChat];
            vc.title=[NSString stringWithFormat:@"%@",self.orderModle.sellerId];
            [self.navigationController pushViewController:vc animated:YES];
            //NSLog(@"联系客服");
        }
            break;
        case 90:
        {
            [self loadreceiveShop:self.orderModle.orderSn];
            //NSLog(@"确认收货");
        }
            break;
        case 35:
        {
            
            NSLog(@"待接单的取消订单");
        }
            break;
        case 45:
        {
            [self nearReachRequest:self.orderModle.orderSn];
            NSLog(@"已到店");
        }
            break;
        case 200:
        {
            [self buyAgain:self.orderModle.items];
            //NSLog(@"再次购买");
        }
            break;
        case 300:
        {
            LXAlertView *alert=[[LXAlertView alloc]initWithTitle:@"提示!" message:@"确定删除该订单?" cancelBtnTitle:@"取消" otherBtnTitle:@"确定" clickIndexBlock:^(NSInteger clickIndex) {
                if (clickIndex==1) {
                    //NSLog(@"删除订单");
                    [self deleteOrder:self.orderModle.orderSn];
                }
            }];
            [alert showLXAlertView];
            
        }
            break;
        default:
            break;
    }

   
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}
#pragma mark-------订单里的商品信息
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.orderModle=self.orderArray[indexPath.section];
    OrdersTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"OrdersCell"];
    cell.model=self.orderModle;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    self.orderModle=self.orderArray[indexPath.section];
    if ([self.orderModle.type intValue]==5||[self.orderModle.type intValue]==6) {
        NearDetailViewController*vc=[[NearDetailViewController alloc]init];
        vc.orderSn=self.orderModle.orderSn;
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        OrderDetailViewController*vc=[[OrderDetailViewController alloc]init];
        vc.orderSn=self.orderModle.orderSn;
        [self.navigationController pushViewController:vc animated:YES];
    }

}
-(void)ordersStypleClick:(UIButton *)sender{
    [self.orderArray removeAllObjects];
    if (self.lastBtn!=sender) {
        sender.selected=YES;
        self.lastBtn.selected=NO;
        self.lastBtn=sender;
        [UIView animateWithDuration:0.35 animations:^{
            self.line.x=sender.x+10;
            self.line.bsg_width=sender.bsg_width-20;
        }];
    }
    switch (sender.tag) {
        case 0:
        {
            [self loadOrderList];
        }
            break;
        case 1:
        {
            [self loadOrderList:100];
        }
            break;
        case 2:
        {
            [self loadOrderList:603];
        }
            break;
            
        case 3:
        {
            [self loadOrderList:600];
        }
            break;
            
        case 4:
        {
            [self loadOrderList:700];
        }
            break;
            

        default:
            break;
    }
}
-(void)loadOrderList:(NSInteger)status{
    NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
    dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"pageNumber"]=@(1);
    dic[@"pageSize"]=@(100);
    dic[@"status"]=@(status);
    [self doHttpRequestWithApi:API_ORDERLIST_LIST method:GET dic:dic successBlock:^(NSDictionary *dic) {
        //NSLog(@"data  数据:%@",dic[@"data"]);
        [self.orderArray addObjectsFromArray:[UserOrderModle mj_objectArrayWithKeyValuesArray:dic[@"data"][@"list"]]];
        if (self.orderArray.count==0) {
            self.blankView.hidden=NO;
        }else{
            self.blankView.hidden=YES;
        }
        [self.tableView reloadData];
    }];
    
}
-(void)loadOrderList{
    NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
    dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"pageNumber"]=@(1);
    dic[@"pageSize"]=@(100);
    [self doHttpRequestWithApi:API_ORDERLIST_LIST method:GET dic:dic successBlock:^(NSDictionary *dic) {
        //NSLog(@"data  数据:%@",dic[@"data"]);
        [self.orderArray addObjectsFromArray:[UserOrderModle mj_objectArrayWithKeyValuesArray:dic[@"data"][@"list"]]];
        if (self.orderArray.count==0) {
            self.blankView.hidden=NO;
        }else{
            self.blankView.hidden=YES;
        }
        [self.tableView reloadData];
        
        
    }];
}
-(void)loadreceiveShop:(NSString *)orderSn{
    NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
    dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"orderSn"]=orderSn;
    [self doHttpRequestWithApi:API_RECEIVESHOP method:POST dic:dic successBlock:^(NSDictionary *dic) {
        //[self.tableView reloadData];
        [MBProgressHUD showSuccess:MyString(@"收货成功")];
        [self dismissDialog];
        [self.orderArray removeAllObjects];
        if (self.lastBtn.tag==0) {
            [self loadOrderList];
        }else{
            [self loadOrderList:600];
        }
        
    }];
}
-(void)buyAgain:(NSArray *)array{
    
    
    NSMutableDictionary *dicc=[NSMutableDictionary dictionary];
    NSMutableArray *Array=[NSMutableArray array];
    for (NSDictionary*dicter in array) {
        [dicc setObject:dicter[@"quantity"] forKey:@"number"];
        [dicc setObject:dicter[@"skuId"] forKey:@"skuId"];
        [Array addObject:dicc];
    }
    
    
    NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
    dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"carts"]=[Array mj_JSONString];
    [self doHttpRequestWithApi:API_BUYAGAIN method:GET dic:dic successBlock:^(NSDictionary *dic) {
        [MBProgressHUD showSuccess:MyString(@"加入购物车")];
//        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//            MianTabBarViewController *tabbar = [[MianTabBarViewController alloc] init];
//            [tabbar setSelectedIndex:2];
//            [UIApplication sharedApplication].keyWindow.rootViewController = tabbar;
//        });
    }];
}
//合并支付
-(void)loadMergeRequest:(UIButton*)ordersn{
    self.orderModle=self.orderArray[ordersn.tag];
    NSArray *array=@[self.orderModle.orderSn];
    NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
    //dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"orders"]=[array mj_JSONString];
    [self doHttpRequestWithApi:BATCHPAY method:GET dic:dic successBlock:^(NSDictionary *dic) {
        PayViewController *vc=[[PayViewController alloc]init];
        vc.orderSn=dic[@"data"][@"payNo"];
        vc.orderDic=[dic[@"data"] copy];
        if ([self.orderModle.type intValue]==4||[self.orderModle.type intValue]==5||[self.orderModle.type intValue]==6) {
            vc.isNear=YES;
        }
        [self.navigationController pushViewController:vc animated:YES];
    }];
}

-(void)deleteOrder:(NSString *)ordersn{
    NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
    dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"orderSn"]=ordersn;
    [self doHttpRequestWithApi:API_REMOVEORDER method:POST dic:dic successBlock:^(NSDictionary *dic) {
        [MBProgressHUD showSuccess:MyString(@"删除成功")];
        [self.orderArray removeAllObjects];
        if (self.lastBtn.tag==0) {
            [self loadOrderList];
        }else{
            [self loadOrderList:700];
        }
    }];
}
-(void)nearReachRequest:(NSString *)orderSn{
    NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
    dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"orderSn"]=orderSn;
    [self doHttpRequestWithApi:NearReach method:POST dic:dic successBlock:^(NSDictionary *dic) {
        if (![dic[@"data"] isEqual:[NSNull null]]) {
            [self loadBATCHPAYRequest:dic[@"data"]];
        }else{
            [self loadOrderList];
        }
    }];
}
-(void)ContactCustomerService:(NSString *)string{
   
}
-(void)loadBATCHPAYRequest:(NSDictionary*)dic{
        PayViewController *vc=[[PayViewController alloc]init];
        vc.orderSn=dic[@"payNo"];
        vc.orderDic=[dic copy];
        if ([self.orderModle.type intValue]==4||[self.orderModle.type intValue]==5||[self.orderModle.type intValue]==6) {
            vc.isNear=YES;
        }
    [self.navigationController pushViewController:vc animated:YES];
}
@end
